#include <string>
#include <algorithm>
using namespace std;
class Solution
{
public:
    int lengthOfLongestSubstring(string s)
    {
        int countMap[200] = {0};
        int maxLen = 0, left = 0, right = 0;
        int len = s.size();
        // int ans = 0;
        while (right < len)
        {
            char tmp = s[right];
            // 说明在原来的序列中不存在该字母
            if (!countMap[tmp])
                countMap[tmp]++;
            // 如果已经在原来的序列存在了
            else
            {
                countMap[tmp]++;
                maxLen = max(maxLen, right - left);
                while (left < right && countMap[tmp] > 1)
                    countMap[s[left++]]--;
            }
            ++right;
        }
        return max(maxLen, right - left);

        // return maxLen;
    }
};